package cn.hzking.gjmall.adpters.nyuan;

import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.activitys.second.WebGoodDetailActivity;
import cn.hzking.gjmall.app.Gjmall;
import cn.hzking.gjmall.bean.NYuanBean;
import cn.hzking.gjmall.utils.OnClickEvent;
import cn.hzking.gjmall.utils.PriceFormatUtils;

/**
 * Created by Administrator on 2018/3/21.
 */

public class NYuanAdapter extends BaseQuickAdapter<NYuanBean.DataBean.ActSkuListBean,BaseViewHolder> {
   private AddCarListener addCarListener;
    private String nyId;//N元选id

    public NYuanAdapter(int layoutResId, @Nullable List<NYuanBean.DataBean.ActSkuListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final NYuanBean.DataBean.ActSkuListBean item) {
        helper.itemView.setOnClickListener(new OnClickEvent() {
            @Override
            public void singleClick(View v) {
                int skuId = item.getSkuId();//skuid
                int spuId = item.getSpuId();//itemId
                WebGoodDetailActivity.startActivity(mContext,WebGoodDetailActivity.NYUAN,String.valueOf(spuId),"",nyId,String.valueOf(skuId));

            }
        });
        //大图片
        final ImageView bigImage = helper.getView(R.id.goodlist_goodimage);
        TextView tvType = helper.getView(R.id.good_type);
        TextView tvTitle = helper.getView(R.id.goodlist_title);
        TextView newPrice = helper.getView(R.id.goodlist_price);
        TextView olderPrice = helper.getView(R.id.goodlist_oldprice);
        JSONArray imageList = JSON.parseArray(item.getImageUrl());
        Glide.with(mContext).load(Gjmall.getOssHost()+imageList.get(0)).placeholder(R.mipmap.xiangqing).error(R.mipmap.xiangqing).into(bigImage);
        //产品类型
        tvType.setText(String.valueOf(item.getSellPattern()));
        //title
        tvTitle.setText(String.valueOf(item.getTitle()));
        //新的价格
        String newPriceS = PriceFormatUtils.valueFormatWithTwo(String.valueOf(item.getPrice()));
        newPrice.setText(String.valueOf(newPriceS));
        //旧的价格
        String olderPriceS = PriceFormatUtils.valueFormatWithTwo(String.valueOf(item.getAvecostPrice()));
        olderPrice.setText(String.valueOf(olderPriceS));
        olderPrice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG); //中划线
        //购物车按钮
       final ImageView imageView =  helper.getView(R.id.addcar);
       imageView.setOnClickListener(new OnClickEvent() {
           @Override
           public void singleClick(View v) {
               if(addCarListener != null){
                   addCarListener.onAdd(imageView,bigImage);
               }
           }
       });

    }


    public interface AddCarListener{
        void  onAdd(ImageView imageView,ImageView showImage);
    }

    public void  setAddCarListener(AddCarListener addCarListener){
        this.addCarListener = addCarListener;
    }

    public void  setNyId(String nyId){
        this.nyId = nyId;
    }
}
